#include <iostream>
using namespace std;

bool p[17], m[17], y[9];
int count, x, env[9];	//x相当于栈顶指针，env相当于栈

void search()
{
	x = 1;
	for(int i = 0; i <= 8; i++)
		env[i] = 1;
	while(x)
	{
		if(x == 9)
		{
			for(int i = 1; i <= 8; i++)
				cout << env[i] << " ";
			cout << endl;
			count++;
			x--;					//Pop
			p[x+env[x]]=0;
			m[x-env[x]+8]=0;
			y[env[x]]=0;
			env[x]++;
		}
		else if(env[x] == 9)
		{
			x--;					//Pop
			p[x+env[x]]=0;
			m[x-env[x]+8]=0;
			y[env[x]]=0;
			env[x]++;
		}
		else if(!p[x+env[x]] && !m[x-env[x]+8] && !y[env[x]])
		{
			p[x+env[x]]=1;
			m[x-env[x]+8]=1;
			y[env[x]]=1;
			x++;					//Push
			env[x] = 1;
		}
		else
			env[x]++;
	}
}

int main()
{
	search();
	cout << count << endl;
	return 0;
}